<template>
  <div id="role">
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item><a href="/home">首页</a></el-breadcrumb-item>
      <el-breadcrumb-item>权限管理</el-breadcrumb-item>
      <el-breadcrumb-item>角色列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 用户列表展示区域 -->
    <el-card>
      <el-table :data="roleList" border stripe>
        <el-table-column
          type="expand"
          class="el-icon-arrow-right"
        ></el-table-column>
        <el-table-column type="index"></el-table-column>
        <el-table-column label="角色名称" prop="roleName"></el-table-column>
        <el-table-column label="角色描述" prop="roleDesc"></el-table-column>
        <el-table-column label="操作">
          <template v-slot:default="scope">
            {{ scope.row.id }}
            <el-button type="primary" icon="el-icon-edit" size="small"
              >编辑</el-button
            >
            <el-button type="danger" icon="el-icon-delete" size="small"
              >删除</el-button
            >
            <el-button type="warning" icon="el-icon-setting" size="small"
              >分配权限</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </el-card>

    <!-- 编辑角色对话框区域 -->
    <el-dialog title="提示" v-model="editRoledialogVisible" width="50%">
      <!-- 内容 -->
      <el-form ref="editRoleForm" :model="editRole" label-width="80px">
        <el-form-item label="角色名称">
          <el-input v-model="editRole.roleName"></el-input>
          <el-input v-model="editRole.roleDesc"></el-input>
        </el-form-item>
      </el-form>
      <!-- 尾部 -->
      <template #footer>
        <span class="dialog-footer">
          <el-button @click="editRoledialogVisible = false">取 消</el-button>
          <el-button type="primary" @click="editRoledialogVisible = false"
            >确 定</el-button
          >
        </span>
      </template>
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: 'Role',
  data() {
    return {
      roleList: [],
      editRoledialogVisible: false,
      editRole: {
        roleId: 0,
        roleName: '',
        roleDesc: '',
      },
    }
  },
  created() {
    this.getRoleList()
  },
  methods: {
    async getRoleList() {
      const { data: res } = await this.$http.get('roles')
      if (res.meta.status !== 200) {
        return this.$message.error('获取角色列表数据失败！')
      }
      this.roleList = res.data
    },
  },
}
</script>

<style>
</style>
